﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using Core.Model;
using Core.Repository;
using Data;
using Service;

namespace IRecConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            var svcUser = new UserService();
            var oUser = new User() {Id = Guid.NewGuid(), LastName = "BENLTAIEF", FirstName = "Bechir"};
            oUser.ModifId = oUser.Id;
            oUser.CreationId = oUser.Id;

            svcUser.Create(oUser);

            var ret= svcUser.Get(oUser.Id);
            ret.DtModif = DateTime.Now;
            svcUser.Save();
        }
    }
}

//using System;
//using System.Collections.Generic;
//using System.Data.Entity;
//using System.Linq;
//using System.Text;
//using System.ComponentModel.DataAnnotations;

//namespace CodeFirstSample
//{
//    class Program
//    {
//        static void Main(string[] args)
//        {
//            Database.SetInitializer<ProductContext>(new DropCreateDatabaseIfModelChanges<ProductContext>());

//            using (var db = new ProductContext())
//            {
//                // Use Find to locate the Food category 
//                var food = db.Categories.Find("FOOD");
//                if (food == null)
//                {
//                    food = new Category { CategoryId = "FOOD", Name = "Foods" };
//                    db.Categories.Add(food);
//                }

//                for (int i = 0; i < 100; i++)
//                {
//                    var product = new Product { Name = string.Format("productName {0}", i), LastName = "fffff", FisrtName ="ggggg", Category = food };
//                    Console.WriteLine(string.Format("Ligne N° {0}", i));
//                    db.Products.Add(product);
//                    db.SaveChanges();
//                }

//                int recordsAffected = db.SaveChanges();

//                Console.WriteLine("Saved {0} entities to the database.", recordsAffected);
//                // Query for all Food products using LINQ 
//                var allFoods = from p in db.Products
//                               where p.CategoryId == "FOOD"
//                               orderby p.Name
//                               select p;

//                Console.WriteLine("All foods in database:");
//                foreach (var item in allFoods)
//                {
//                    Console.WriteLine(" - {0}", item.Name);
//                }

//                Console.WriteLine("Press any key to exit.");
//                Console.ReadKey();


//            }
//        }
//    }
//    public class Category
//    {
//        public string CategoryId { get; set; }
//        public string Name { get; set; }

//        public virtual ICollection<Product> Products { get; set; }
//    }

//    public class Product
//    {
//        public int ProductId { get; set; }
//        public string Name { get; set; }
//        public string LastName { get; set; }
//        public string FisrtName { get; set; }
//        public string CategoryId { get; set; }

//        public virtual Category Category { get; set; }
//    }
//    public class ProductContext : DbContext
//    {
//        public ProductContext()
//            : base("DbProduct1")
//        {
//        }

//        public DbSet<Category> Categories { get; set; }
//        public DbSet<Product> Products { get; set; }
//        public DbSet<Supplier> Suppliers { get; set; }

//        protected override void OnModelCreating(DbModelBuilder modelBuilder)
//        {
//            modelBuilder.Entity<Supplier>().Property(s => s.Name).IsRequired();
//        }

//    }
//    public class Supplier
//    {
//        [Key]
//        public string SupplierCode { get; set; }
//        public string Name { get; set; }
//    }

//}